<?php
namespace App\Admin\Models;
use Common\BaseModel;
class CollegeCategories extends BaseModel
{
    protected $res;
    protected $key="admin_";
    public function initialize()
    {
        parent::initialize();
        $this->setSource('f_college_categories');
    }


    /**
     * 获取栏目下面的分类
     * @param int $cid 栏目id
     * @return mixed
     */
    public function find_list($params){
        $conditions="is_show=1";
        if(isset($params['cateid']) && !empty($params['cateid'])){
            $conditions .= " AND cid={$params['cateid']}";
        }
        if(isset($params['keywords']) && !empty($params['keywords'])){
            $conditions .= " AND name like '%{$params['keywords']}%'";
        }
        $order="sort ASC,id ASC";
        $carousel_list = $this::find(
            array(
                $conditions,
                "order" => $order,
                "cloumns"=>""
            )
        );
        return $carousel_list;
    }


    /**
     * 根据id获取分类
     */
    public function find_by_id($id){
        $info = $this->findFirstById($id);
        if($info){
            return $info->toarray();
        }else{
            return [];
        }
    }



    /**
     * 根据id获取分类
     */
    public function find_count($cateid){
        $conditions="cid={$cateid}";
        $carousel_list = $this::count(
            array(
                $conditions,
                "cloumns"=>"id"
            )
        );
        return $carousel_list;
    }


    public function save_params($params){
        return $this::save($params);
    }





}
